﻿using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GPSTestApp
{
    public partial class Program
    {
        GTM.Seeed.GPS gps;

        void ProgramStarted()
        {
            /******************************************************************************************
            Access modules defined in the designer by typing their name:                            
            
            e.g.  button
                  camera1

            Initialize event handlers here.
            e.g. button.ButtonPressed += new GTM.MSR.Button.ButtonEventHandler(button_ButtonPressed);             
            ***************************************************************************************** */

            gps = new GTM.Seeed.GPS(8);
//            gps.DebugPrintEnabled = true;
            gps.InvalidPositionReceived += new GTM.Seeed.GPS.InvalidPositionReceivedHandler(gps_InvalidPositionReceived);
            gps.PositionReceived += new GTM.Seeed.GPS.PositionReceivedHandler(gps_PositionReceived);

            GT.Timer timer = new GT.Timer(5000);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();

            // Do one-time tasks here
            Debug.Print("Program Started");
        }

        void timer_Tick(GT.Timer timer)
        {
            Debug.Print("GPS last position " + gps.LastPosition + " age " + gps.LastValidPositionAge);
        }

        void gps_InvalidPositionReceived(GTM.Seeed.GPS sender)
        {
            Debug.Print("Invalid position");
        }

        void gps_PositionReceived(GTM.Seeed.GPS sender, GTM.Seeed.GPS.Position position)
        {
            Debug.Print(position);
        }
    }
}
